package kr.co.boogui.actions.news;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.boogui.actions.ActionHandler;
import kr.co.boogui.dao.NewsDAO;

public class NewsViewAction implements ActionHandler {
	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		//String newsno =req.getParameter("newwsno");
		int newsno = Integer.parseInt(req.getParameter("newsno"));
		req.setAttribute("action", "../news/news_view.jsp");
		req.setAttribute("news", NewsDAO.viewBoard(newsno));
		
		int newstype =0;
		for (int i = 0; i < 4; i++) {
			newstype=i;
			switch (newstype) {
			case 1:
				req.setAttribute("count1", NewsDAO.manyNews(newstype));
				req.setAttribute("prev1", NewsDAO.prvNews(newstype,newsno));
				req.setAttribute("next1", NewsDAO.nextNews(newstype,newsno));
				System.out.println("타입"+newstype);
				break;
			case 2:
				req.setAttribute("count2", NewsDAO.manyNews(newstype));
				req.setAttribute("prev2", NewsDAO.prvNews(newstype,newsno));
				req.setAttribute("next2", NewsDAO.nextNews(newstype,newsno));
				System.out.println("타입"+newstype);
				break;
			case 3:
				req.setAttribute("count3", NewsDAO.manyNews(newstype));
				req.setAttribute("prev3", NewsDAO.prvNews(newstype,newsno));
				req.setAttribute("next3", NewsDAO.nextNews(newstype,newsno));
				System.out.println("타입"+newstype);
				break;
			}
		}
		
	

		NewsDAO.viewCountNews(newsno);
		String viewPage = "f|/WEB-INF/jsp/tiles/index.jsp";

		return viewPage;
	}

}
